package com.wanpinghui.supplier.user.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wanpinghui.supplier.R;
import com.wanpinghui.wphlibrary.model.user.bean.CreditRuleBean;
import com.yunshl.yunshllibrary.recyclerview.BaseRecyclerViewAdapter;

/**
 * Created by Administrator on 2017/12/14.
 */

public class CreditRuleAdapter extends BaseRecyclerViewAdapter<CreditRuleBean, CreditRuleAdapter.CreditRuleViewHolder> {


    public CreditRuleAdapter(Context context) {
        super(context);
    }

    @Override
    public CreditRuleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_chengjiuzhi, parent, false);
        return new CreditRuleViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CreditRuleViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.tv_content.setText(datas.get(position).getName());
        if (datas.get(position).getValue() < 0) {
            holder.tv_count.setText(Integer.toString(datas.get(position).getValue()));
        } else {
            holder.tv_count.setText("+" + datas.get(position).getValue());
        }
    }


    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    class CreditRuleViewHolder extends RecyclerView.ViewHolder {

        TextView tv_content;
        TextView tv_count;

        public CreditRuleViewHolder(View itemView) {
            super(itemView);
            tv_content = (TextView) itemView.findViewById(R.id.tv_content);
            tv_count = (TextView) itemView.findViewById(R.id.tv_count);
        }
    }
}
